//
// Created by REEJI2219 on 2024-08-14.
//
#include <iostream>
using namespace std;
typedef int Element;
class CircleQueue {
private:
    int front;//头位置
    int rear;//尾位置
    int size;
    Element *array;
public:
    CircleQueue(){
        this->size=6;
        this->rear=0;
        this->front=0;
        array = new Element[this->size];
    }
    ~CircleQueue() {
        delete[] array;
    }
    bool enQueue(Element element) {
        //队列已满
        if((rear+1)%size==front) {
            return false;
        }
        array[rear]=element;
        rear=(rear+1)%size;
        return true;
    }
    bool deQueue(Element *element) {
        //头等于尾，说明队列已经被清空了
        if(front==rear) {
            return false;
        }
        *element = array[front];
        array[front]=0;
        front=(front+1)%size;
        return true;
    }
    int length() {
        return (rear-front+size)%size;
    }
    void printQueue() {
        int length= this->length();
        for(int i= 0;i<length;i++) {
            printf("%d ",array[(front+i)%size]);
        }
        printf("\n");
    }
};

// int main(int argc, char *argv[]) {
//     CircleQueue *circleQueue = new CircleQueue();
//     circleQueue->enQueue(1);
//     circleQueue->enQueue(2);
//     circleQueue->enQueue(3);
//     circleQueue->enQueue(4);
//     circleQueue->enQueue(5);
//     circleQueue->enQueue(6);
//     circleQueue->printQueue();
//     Element out;
//     circleQueue->deQueue(&out);
//     cout<<out<<endl;
//     circleQueue->deQueue(&out);
//     cout<<out<<endl;
//     circleQueue->enQueue(7);
//     circleQueue->enQueue(8);
//     circleQueue->enQueue(9);
//     circleQueue->printQueue();
// }
